<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2015 http://www.itaoke.org All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author:  Caption <Caption@163.com> QQ 1674653
// +----------------------------------------------------------------------
namespace Home\Controller;
use Common\Controller\FirstendController;

class DogController extends FirstendController {
	
	public function index(){
		
		$auth=I('auth','');
		if($auth!=C('itk_auto_auth'))
			return;
		
		$isq=I('isq',0);
		if($isq!=0)
			$where['isq']=1;
		

		$where['dx']=1;			//  只申请强制定向的
		$where['ding']=0;		//	只申请未处理过的
		$where['coupon_end_time']= array('EGT',time());
		$where['status'] ='underway';
				
		$_r=M('Items')->where($where)->field("num_iid,title,intro,quanurl,coupon_price,quan,commission_rate,(coupon_price-quan) as after_price")->select();
		$this->ajaxReturn(0,'SUCCESS',$_r);
	}
	
	/**
	 * 用于批量记录淘优惠与狗对接
	 */
	public function updateItem(){
		$dog_data=I('dog_data');
		if($dog_data=='')
			return;
		$_param=array(
				'num_iid'=>'',
				'auth'=>'',
		);
		$arr=explode('|', $dog_data);
		for($i=0;$i<count($arr);$i++){
			$param=explode('=', $arr[$i]);
			$_param[$param[0]]=$param[1];
		}
		
		if($_param['auth']!=C('itk_auto_auth'))
			return;

		if($_param['num_iid']=='')
			return;
		\Think\Log::record('num_iid'.$_param['num_iid']);
		\Think\Log::record('auth'.$_param['auth']);
		
		M('Items')->where(array('num_iid'=>$_param['num_iid']))->save(
			array(
				'ding'=>1
			)
		);
	}
}